package com.edu.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.edu.commonutils.R;
import com.edu.eduservice.domain.EduCourse;
import com.edu.eduservice.domain.EduTeacher;
import com.edu.eduservice.service.EduCourseService;
import com.edu.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName IndexFrontController
 * @date 2022/9/22 9:17
 * @Version 1.0
 */
//@CrossOrigin
@Api(description = "前台显示接口")
@RestController
    @RequestMapping("/eduservice/indexfront")
public class IndexFrontController {

    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduTeacherService eduTeacherService;

    @ApiOperation("前台显示讲师和课程")
    @GetMapping("/frontShow")
    @ResponseBody
    public R getFront(){
        //只要前面两条记录
        QueryWrapper<EduCourse> wrapper=new QueryWrapper();
        wrapper.orderByDesc("id");//根据id降序
        wrapper.last(" limit 8");//有last拼接语句 来得到前面两条数据

        List<EduCourse> list = this.eduCourseService.list(wrapper);

        //只要前面两条记录
        QueryWrapper<EduTeacher> wrapper2=new QueryWrapper();
        wrapper2.orderByDesc("id");//根据id降序
        wrapper2.last(" limit 4");//有last拼接语句 来得到前面两条数据

        List<EduTeacher> teachers = eduTeacherService.list(wrapper2);

        return R.ok().data("courses",list).data("teachers",teachers);
    }


}
